package thread;

/**
 * @author zxl
 * @version 1.0
 * @date 2021/10/26 17:39
 * 线程礼让
 * 停止当前的线程，让所有的线程都在就绪状态
 * 礼让不一定能成功
 */
public class ThreadYield {
    public static void main(String[] args) {
        Threads threads = new Threads();
        new Thread(threads, "a").start();
        new Thread(threads, "b").start();

    }
}
class Threads implements Runnable {
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "开始");
        Thread.yield();  //礼让
        System.out.println(Thread.currentThread().getName() + "结束");
    }
}
